//
//  MainActivityCell.m
//  Rabbit
//
//  Created by 阿帕 on 2018/11/4.
//  Copyright © 2018年 GCY. All rights reserved.
//

#import "CarSourceCell.h"

@interface CarSourceCell ()
@property (weak, nonatomic) IBOutlet UILabel *zhuangAdressLabel;
@property (weak, nonatomic) IBOutlet UILabel *xieAdressLabel;
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *carInfoLabel;
@property (weak, nonatomic) IBOutlet UIView *buttonBgView;
@property (weak, nonatomic) IBOutlet UIView *topLine;
@property (weak, nonatomic) IBOutlet UIView *bottonLine;

@end

@implementation CarSourceCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _zhuangAdressLabel.textColor = Dark_TextColor;
    _xieAdressLabel.textColor = Dark_TextColor;
    _carInfoLabel.textColor = Light_TextColor;
    _topLine.backgroundColor = BackgroundColor;
    _bottonLine.backgroundColor = BackgroundColor;

    NSArray *btnTitles = @[@"编辑", @"删除"];
    NSArray *btnImages = @[@"gcy_icon_yundan_edit", @"gcy_icon_yundan_delete"];
    for (int i=0; i<btnTitles.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = 100 + i;
        [button setBackgroundColor:[UIColor whiteColor]];
        [button setTitle:btnTitles[i] forState:UIControlStateNormal];
        button.titleLabel.font = font(14);
        [button setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        [button setImage:image(btnImages[i]) forState:UIControlStateNormal];
        button.frame = CGRectMake(ScreenW/btnTitles.count*i, 0, ScreenW/btnTitles.count,_buttonBgView.cy_height);
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_buttonBgView addSubview:button];
        
        [button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
        
    }
}

- (void)setModel:(CarSourceRecordModel *)model {
    
    _model = model;
    
    _zhuangAdressLabel.text = model.departure;
    _xieAdressLabel.text = model.destination;
//    _carInfoLabel.text = CJStringWithFormat(@"%@ %@%@ %@", model.content, model.loadStatusName, model.loadStatus, model.vehicleTypeName);
    _carInfoLabel.text = CJStringWithFormat(@"%@", model.content);
    [_headImageView setImageWithURL:[NSURL URLWithString:model.headImg] placeholder:image(@"gcy_img_main_head")];
}

- (void)buttonClick:(UIButton *)button {
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(cellButtonIndexClick:withButton:)]) {
        [self.delegate cellButtonIndexClick:button.tag withButton:button];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
